package com.zhongen.oa.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongen.common.core.util.R;
import com.zhongen.common.log.annotation.SysLog;
import com.zhongen.oa.entity.ProjectReimburseRelationshipEntity;
import com.zhongen.oa.service.ProjectReimburseRelationshipService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 项目报销关系表
 *
 * @author Code Generator
 * @date 2024-01-22 17:10:19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/projectReimburseRelationship")
@Tag(description = "projectReimburseRelationship", name = "项目报销关系表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ProjectReimburseRelationshipController {

	private final ProjectReimburseRelationshipService projectReimburseRelationshipService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param projectReimburseRelationship 项目报销关系表
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('oa_projectReimburseRelationship_view')")
	public R getProjectReimburseRelationshipPage(@ParameterObject Page page,
			@ParameterObject ProjectReimburseRelationshipEntity projectReimburseRelationship) {
		LambdaQueryWrapper<ProjectReimburseRelationshipEntity> wrapper = Wrappers.lambdaQuery();
		return R.ok(projectReimburseRelationshipService.page(page, wrapper));
	}

	/**
	 * 通过id查询项目报销关系表
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('oa_projectReimburseRelationship_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(projectReimburseRelationshipService.getById(id));
	}

	/**
	 * 新增项目报销关系表
	 * @param projectReimburseRelationship 项目报销关系表
	 * @return R
	 */
	@Operation(summary = "新增项目报销关系表", description = "新增项目报销关系表")
	@SysLog("新增项目报销关系表")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('oa_projectReimburseRelationship_add')")
	public R save(@RequestBody ProjectReimburseRelationshipEntity projectReimburseRelationship) {
		return R.ok(projectReimburseRelationshipService.save(projectReimburseRelationship));
	}

	/**
	 * 修改项目报销关系表
	 * @param projectReimburseRelationship 项目报销关系表
	 * @return R
	 */
	@Operation(summary = "修改项目报销关系表", description = "修改项目报销关系表")
	@SysLog("修改项目报销关系表")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('oa_projectReimburseRelationship_edit')")
	public R updateById(@RequestBody ProjectReimburseRelationshipEntity projectReimburseRelationship) {
		return R.ok(projectReimburseRelationshipService.updateById(projectReimburseRelationship));
	}

	/**
	 * 通过id删除项目报销关系表
	 * @param ids id列表
	 * @return R
	 */
	@Operation(summary = "通过id删除项目报销关系表", description = "通过id删除项目报销关系表")
	@SysLog("通过id删除项目报销关系表")
	@DeleteMapping
	@PreAuthorize("@pms.hasPermission('oa_projectReimburseRelationship_del')")
	public R removeById(@RequestBody Long[] ids) {
		return R.ok(projectReimburseRelationshipService.removeBatchByIds(CollUtil.toList(ids)));
	}

	/**
	 * 导出excel 表格
	 * @param projectReimburseRelationship 查询条件
	 * @param ids 导出指定ID
	 * @return excel 文件流
	 */
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('oa_projectReimburseRelationship_export')")
	public List<ProjectReimburseRelationshipEntity> export(
			ProjectReimburseRelationshipEntity projectReimburseRelationship, Long[] ids) {
		return projectReimburseRelationshipService.list(Wrappers.lambdaQuery(projectReimburseRelationship)
			.in(ArrayUtil.isNotEmpty(ids), ProjectReimburseRelationshipEntity::getId, ids));
	}

}